package com.stone.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {

    public static void main(String[] args) {
        excute2();
    }

    public static void excute1() {
        StoneThreadPool pool = new StoneThreadPool(2, 4, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(2));
        for (int i = 0; i < 10; i++) {
            pool.execute(new ITask() {
                @Override
                public void execute() {
                    System.err.println(Thread.currentThread().getName() + " 剪头发 .");
                }
            });
        }
    }

    public static void excute2() {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                2,
                4,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new StoneRejectedExecutionHandler());
        for (int i = 0; i < 20; i++) {
            executor.execute(new Thread(() -> {
                System.err.println(Thread.currentThread().getName() + " 执行任务 .");
            }));
        }

    }
}
